package com.weixin.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;

import org.apache.logging.log4j.Logger;

public class WeixinConfigUtil {

	// 欠费模版id
	public static String TEMPLATE_IN_DEBT = "TEMPLATE_ID_INDEBT";
	// 余额不足id
	public static String TEMPLATE_BALANCE = "TEMPLATE_ID_BALANCE";
	// 余额不足id
	public static String TEMPLATE_PAY = "TEMPLATE_ID_PAY";
	// 任务到期提醒id
	public static String TEMPLATE_ID_TASK_ARRIVE = "TEMPLATE_ID_TASK_ARRIVE";
	// 充值成功提醒id
	public static String TEMPLATE_ID_CHONGZHI = "TEMPLATE_ID_CHONGZHI";
	// 预约成功提醒
	public static String TEMPLATE_ID_ORDER = "TEMPLATE_ID_ORDER";

	private static Logger logger;
	// weixin property
	private static Properties weiXinProperties;
	// weixin.property file path
	private static final String CONFIG_PATH = "weixin.property";
	// weixin property : appid
	private static final String APPID_NAME = "APPID";
	// weixin property : appsecret
	private static final String APPSECRET = "APPSECRET";

	private static Properties getInstance() throws IOException {
		if (weiXinProperties == null) {
			try {
				InputStream in = WeixinConfigUtil.class.getClassLoader().getResourceAsStream(CONFIG_PATH);
				weiXinProperties = new Properties();
				weiXinProperties.load(in);
			} catch (IOException e) {
				e.printStackTrace();
				logger.error("weixin.jar get weixin.property failed , please check weixin.property under src folder");
				logger.error("catch exception : " + WeixinCommonUtil.getStackTrace(e));
				throw new IOException("没有找到weixin.property配置文件，请检查其是否放置在src目录下!", e);
			}
		}

		return weiXinProperties;
	}

	/**
	 * get APPID from weicin.property
	 * 
	 * @return
	 * @throws IOException
	 */
	public static String getAppId() throws IOException {
		return getInstance().get("APPID").toString();
	}

	/**
	 * getAPPSECRET
	 * 
	 * @return
	 * @throws IOException
	 */
	public static String getAppSecret() throws IOException {
		return getInstance().getProperty("APPSECRET").toString();
	}

	public static String getPartner_key() {
		// TODO Auto-generated method stub
		return null;
	}

	public static String getAppKey() {
		// TODO Auto-generated method stub
		return null;
	}

	public static String getNotify_url() {
		// TODO Auto-generated method stub
		return null;
	}

	public static String getPartner_Id() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 获取模版消息
	 * 
	 * @return
	 * @throws IOException
	 */
	public static String getTemplate_id(String template_id) throws IOException {
		return getInstance().get(template_id).toString();
	}

}
